//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<expose_editor_to_python.cpp>
///	@path	~/src/editor/wrap/
///	@date	2008/10/23
///	@desc	.

#define _FULLAPI
#include "config/config.h"

#include "lib/utilities/debug.h"
#include "lib/utilities/observer.h"

#include "editor/wm/XFormView.h"
#include "editor/wm/XFrameView.h"
#include "editor/xedit/XEditorFrame.h"
#include "editor/wrap/expose_editor_to_python.h"
#include "editor/wm/XWindowManager.h"

namespace xeres {

	namespace
	{
		int OpenDialogWrap( Ref<XForm> form )
		{
			return editor::wm().OpenDialog( form );
		}

		void CloseDialogWrap( int result )
		{
			editor::wm().CloseDialog( result );
		}
	}

	static void expose_editor_ui( void )
	{
		class_< XEditorFrame , Ref<XEditorFrame> , bases< XFrame > , noncopyable >( "XEditorFrame" , no_init )
			// Methods.
		;
		register_object_to_python<XEditorFrame>();

		def( "OpenDialog" , &OpenDialogWrap );
		def( "CloseDialog" , &CloseDialogWrap );
	}

	static void expose_editor_main( void )
	{
		// register main frame views.
		PythonPlug::instance().RegisterObject( "editor" , "shelf" ,
			object( Ref<XEditorFrame>( editor::wm().GetMain().GetShelf().GetFrame() ) ) );
		PythonPlug::instance().RegisterObject( "editor" , "tools" ,
			object( Ref<XEditorFrame>( editor::wm().GetMain().GetTools().GetFrame() ) ) );
		PythonPlug::instance().RegisterObject( "editor" , "panel" ,
			object( Ref<XEditorFrame>( editor::wm().GetMain().GetPanel().GetFrame() ) ) );
		PythonPlug::instance().RegisterObject( "editor" , "operation" ,
			object( Ref<XEditorFrame>( editor::wm().GetMain().GetOperation().GetFrame() ) ) );
		PythonPlug::instance().RegisterObject( "editor" , "shell" ,
			object( Ref<XEditorFrame>( editor::wm().GetMain().GetShell().GetFrame() ) ) );
		PythonPlug::instance().RegisterObject( "editor" , "cue" ,
			object( Ref<XEditorFrame>( editor::wm().GetMain().GetCue().GetFrame() ) ) );
	}

	namespace
	{
#define dllimport		noinline
		BOOST_PYTHON_MODULE( editor )
		{
			expose_editor_ui();
			expose_editor_main();
		}
	}
	
	// expose_editor_to_python
	void expose_editor_to_python( void )
	{
		PythonPlug::instance().RegisterModule( "editor" , init_module_editor );
	}

} // namespace xeres
